﻿using System;
using System.Collections.Generic;

namespace CSharpExt.Collections.Concurrent
{
    public class ConcurrentDictionary<TKey, TValue> : Dictionary<TKey, TValue>
    {
        #region Operations

        public new void Clear()
        {
            lock (this)
            {
                base.Clear();
            }

        }

        public void Add(TKey key, TValue value)
        {
            lock (this)
            {
                base.Add(key, value);
            }
        }

        public bool SetValue(TKey key, TValue value)
        {
            lock(this)
            {
                bool exists = !base.ContainsKey(key);
                base[key] = value;
                return !exists;
            }
        }

        public TValue GetValue(TKey key)
        {
            lock (this)
            {
                return base[key];
            }
        }

        public bool TryGetValue(TKey key, out TValue value)
        {
            lock (this)
            {
                return base.TryGetValue(key, out value);
            }
        }

        #endregion
    }
}
